//
//  DBDaoHelper.m
//  E-Book
//

#import "DBDaoHelper.h"
#import "DBHelper.h"

@implementation DBDaoHelper
//创建数据库表
//+(BOOL)createTableWithSql:(NSString *)sql{
//    FMDatabase *db =[DBHelper openDatabase:@"users.db"];
//    BOOL result = [db executeUpdate:sql];
//    [db close];
//    return result;
//}

//创建数据库表
+(BOOL)createTableWithSql:(NSString *)sql{
    FMDatabase *db =[DBHelper openDatabase:@"data.db"];
    BOOL result = [db executeUpdate:sql];
    [db close];
    return result;
}

//输入sql语句来更新数据库
+(BOOL)updateTableData:(NSString *)sql{
    FMDatabase *db =[DBHelper openDatabase:@"data.db"];
    BOOL result = [db executeUpdate:sql];
    [db close];
    return result;
}

//查询数据库
+(FMResultSet *)selectDataWithSql:(NSString *)sql{
    FMDatabase *db =[DBHelper openDatabase:@"data.db"];
//    NSMutableArray *arr = [[NSMutableArray alloc]init];
    if (sql == nil) {
        return nil;
    }
    //执行查询语句
    FMResultSet *result = [db executeQuery:sql];
    return result;
//    while (result.next)
//    {
//        //根据列名取得数据
//        NSString *strBook = [result stringForColumn:@"book_id"];
//        //根据列号取得数据
//        NSString *strTitle = [result stringForColumn:@"title"];
//        NSString *strContent = [result stringForColumn:@"content"];
//        NSString *strTime = [result stringForColumn:@"time"];
//        NSString *strImgurl = [result stringForColumn:@"imgurl"];
//        NSString *strtype = [result stringForColumn:@"book_type"];
//        //电子书对象添加到数组中
//        ShowListModel * book = [[ShowListModel alloc]init];
//        book.book_id = strBook;
//        book.title = strTitle;
//        book.content = strContent;
//        book.time = strTime;
//        book.imgurl = strImgurl;
//        book.book_type = strtype;
//        [arr addObject:book];
//    }
//    return arr;
}

@end
